package com.example.kbase.util;

import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream;

public class Utils {
    public static String getTextFromStream(InputStream is) {
        byte[] buffer = new byte[1024];
        int len ;
        ByteArrayOutputStream bos = new ByteArrayOutputStream();
        try {
            while((len = is.read(buffer)) != -1) {
                bos.write(buffer, 0, len);
            }
            //利用字节数组输出流转换成字节数组，然后用字节数组构造成为一个字符串
            String text = new String(bos.toByteArray());
            return text;
        } catch (IOException e) {
            e.printStackTrace();
        }
        return "";
    }

}
